package com.example.demo;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.example.util.redisUtil;


@RestController
public class redisController {
	
	@Autowired
	private redisUtil redisutil;

    /**
     * 设置Str缓存
     * @param key
     * @param val
     * @return
     */
    @RequestMapping(value = "setStr")
    public String setStr(String key, String val,@RequestParam(value="faile" ,required=true)String failee ){
    	System.out.println(key+","+val+","+failee);
        try {
        	redisutil.setStr(key, val);
            return "success";
        } catch (Exception e){
            e.printStackTrace();
            return "error";
        }
    }

    /**
     * 根据key查询Str缓存
     * @param key
     * @return
     */
    @RequestMapping(value = "getStr")
    public String getStr(String key){
    	 return redisutil.getStr(key);
    }

    /**
     * 根据key产出Str缓存
     * @param key
     * @return
     */
    @RequestMapping(value = "delStr")
    public String delStr(String key){
        try {
        	redisutil.del(key);
            return "success";
        } catch (Exception e){
            return "error";
        }
    }


    /**
     * 获取obj缓存
     * @param key
     * @return
     */
    @RequestMapping(value = "getObj")
    public Object getObj(String key){
        return redisutil.getObj(key);
    }


    /**
     * 删除obj缓存
     * @param key
     * @return
     */
    @RequestMapping(value = "delObj")
    public Object delObj(String key){
        try {
        	redisutil.delObj(key);
            return "success";
        } catch (Exception e){
            e.printStackTrace();
            return "error";
        }
    }
    /**
     * 删除obj缓存
     * @param key
     * @return
     */
    @RequestMapping(value = "getAllHash")
    public Object getAllHash(String key){
        	redisutil.hashGet(key);
            return "success";
    }

}
